version 16
* pause on

*******************   COMPUTING EQUILIBRIUM OUTCOMES UNDER PROCrp

* use PROCmodel_data.dta, replace
* drop if vot_right==1
* by issue_id, sort: egen poptot = total(pop)

*  Compute most reformist country position
gsort issue_id cntry_pos
by issue_id: egen pivot_top=max(cntry_pos)

*  Compute pivot unanimity
gsort issue_id -cntry_pos
gen pivot_u=cntry_pos if issue_id!=issue_id[_n+1]

replace pivot_top=. if pivot_u==. /* to keep pivot_pop pivot_u on the same row */

* Compute pivot qmv
gen cumvote=votes_cou if cou_rule==2
local j = 1
while `j' <= 759 {
replace cumvote=cumvote+cumvote[_n-1] in `j' if issue_id==issue_id[_n-1]
local j = `j' + 1
}
generate pivot_qmv=cntry_pos if cumvote>=62 &   act==2 & cou_rule==2
replace pivot_qmv=cntry_pos 	if cumvote>=232 & (act==1 | act==3) & cou_rule==2
replace pivot_qmv=cntry_pos if cumvote>=255 & (act==4 | act==9  | act==11) & cou_rule==2
replace pivot_qmv=cntry_pos if cumvote>=157 & (act==8 | act==10 | act==12 | act==13) & cou_rule==2
replace pivot_qmv=pivot_qmv[_n-1] if pivot_qmv[_n-1]!=. & issue_id==issue_id[_n-1] & cou_rule==2 /* to ensure that the pivot value is the same in the column */

* Compute pivot in number of member states (14 & 9)
gen cumcount=1 if cou_rule==2
local j = 1
while `j' <= 759 {
replace cumcount=cumcount+cumcount[_n-1] in `j' if issue_id==issue_id[_n-1]
local j = `j' + 1
}
gen pivot_count14=cntry_pos if cumcount>=14 & cou_rule==2
replace pivot_count14=pivot_count14[_n-1] if pivot_count14[_n-1]!=. & issue_id==issue_id[_n-1] & cou_rule==2  /* to ensure that the pivot value is the same in the column */
gen pivot_count9=cntry_pos if cumcount>=9 & cou_rule==2
replace pivot_count9=pivot_count9[_n-1] if pivot_count9[_n-1]!=. & issue_id==issue_id[_n-1] & cou_rule==2  /* to ensure that the pivot value is the same in the column */

* Compute pivot in population
gen pop_s=pop/poptot
gen cumpop=pop_s if cou_rule==2
local j = 1
while `j' <= 759 {
replace cumpop=cumpop+cumpop[_n-1] in `j' if issue_id==issue_id[_n-1]
local j = `j' + 1
}
gen pivot_pop=cntry_pos if cumpop>=0.62 & cou_rule==2
replace pivot_pop=pivot_pop[_n-1] if pivot_pop[_n-1]!=. & issue_id==issue_id[_n-1] & cou_rule==2  /* to ensure that the pivot value is the same in the column */

* Compute pivot in qmv with pop rule and all member states 
egen pivot_min14=rowmin(pivot_qmv pivot_count14 pivot_pop) if pivot_qmv!=. & pivot_count14!=. & pivot_pop!=. & issue_id!=issue_id[_n+1]

* Compute pivot in qmv with pop rule and eurozone member states 
egen pivot_min9=rowmin(pivot_qmv pivot_count9 pivot_pop) if pivot_qmv!=. & pivot_count9!=. & pivot_pop!=. & issue_id!=issue_id[_n+1]

* pause

***** Compute PROC model prediction
*** Unanimity: the intersection U=A_1 ∩ S as the set of proposals that can be adopted under the unanimity-based consultation procedure (act 5, 6, 7 & baseline for other acts)
* strongly conservative Commission
gen PROCrp=pivot_u       if pivot_u>=comm
* moderately conservative Commission (distant pivot_u pivot_top)
replace PROCrp=comm      if pivot_u<=comm & comm<=pivot_top & 2*pivot_u<=pivot_top & comm<=2*pivot_u
* centrist Commission (close pivot_u pivot_top)
replace PROCrp=comm      if pivot_u<=comm & comm<=pivot_top & 2*pivot_u>=pivot_top
* moderately reformist Commission (distant pivot_u pivot_top)
replace PROCrp=2*pivot_u if pivot_u<=comm & comm<=pivot_top & comm>=2*pivot_u & 2*pivot_u<=pivot_top  
* reformist Commission (close pivot_u pivot_top)
replace PROCrp=pivot_top if comm>=pivot_top & 2*pivot_u>=pivot_top  

* pause

*** QMV Consultation (2005) with qmv: Q=A_3 ∩ S is the set of proposals that can be adopted under the qualified majority-based consultation procedure (act 1)
* strongly conservative Commission - as unanimity
* moderately conservative Commission
replace PROCrp=comm        if pivot_u<=comm & comm<=pivot_qmv & cou_rule==2 & ep_rule==1 & act==1
* moderately conservative Commission (distant pivot_qmv pivot_top)
replace PROCrp=comm        if pivot_qmv<=comm & comm<=pivot_top & 2*pivot_qmv<=pivot_top & comm<=2*pivot_qmv & cou_rule==2 & ep_rule==1 & act==1
* centrist Commission (close pivot_qmv pivot_top)
replace PROCrp=comm        if pivot_qmv<=comm & comm<=pivot_top & 2*pivot_qmv>=pivot_top & cou_rule==2 & ep_rule==1 & act==1
* moderately reformist Commission (distant pivot_qmv pivot_top)
replace PROCrp=2*pivot_qmv if pivot_qmv<=comm & comm<=pivot_top & comm>=2*pivot_qmv & 2*pivot_qmv<=pivot_top & cou_rule==2 & ep_rule==1 & act==1 
* reformist Commission (close pivot_qmv pivot_top)
replace PROCrp=pivot_top if comm>=pivot_top & 2*pivot_qmv>=pivot_top & cou_rule==2 & ep_rule==1 & act==1 

* pause

*** QMV Consultation (2011) all countries qmv min14 : Q=A_3 ∩ S is the set of proposals that can be adopted under the qualified majority-based consultation procedure (act 11)
* strongly conservative Commission - as unanimity
* moderately conservative Commission
replace PROCrp=comm        if pivot_u<=comm & comm<=pivot_min14 & cou_rule==2 & ep_rule==1 & act==11
* moderately conservative Commission (distant pivot_min14 pivot_top)
replace PROCrp=comm        if pivot_min14<=comm & comm<=pivot_top & 2*pivot_min14<=pivot_top & comm<=2*pivot_min14 & cou_rule==2 & ep_rule==1 & act==11
* centrist Commission (close pivot_min14 pivot_top)
replace PROCrp=comm        if pivot_min14<=comm & comm<=pivot_top & 2*pivot_min14>=pivot_top & cou_rule==2 & ep_rule==1 & act==11
* moderately reformist Commission (distant pivot_min14 pivot_top)
replace PROCrp=2*pivot_min14 if pivot_min14<=comm & comm<=pivot_top & comm>=2*pivot_min14 & 2*pivot_min14<=pivot_top & cou_rule==2 & ep_rule==1 & act==11 
* reformist Commission (close pivot_min14 pivot_top)
replace PROCrp=pivot_top if comm>=pivot_top & 2*pivot_min14>=pivot_top & cou_rule==2 & ep_rule==1 & act==11 

* pause

*** Cooperation (acts 2 and 3) with qmv
* The set of proposals that can be adopted under cooperation is C=A_3 ∩ (A_p ∪ A_1 ) ∩ S, where A_p is the Parliament’s acceptance set
* first step an qmv
* strongly conservative Commission - as unanimity
* moderately conservative Commission
replace PROCrp=comm        if pivot_u<=comm & comm<=pivot_qmv & cou_rule==2 & ep_rule==1 & (act==2 | act==3)
** moderately conservative Commission (distant pivot_qmv pivot_top)
replace PROCrp=comm        if pivot_qmv<=comm & comm<=pivot_top & 2*pivot_qmv<=pivot_top & comm<=2*pivot_qmv & cou_rule==2 & ep_rule==1 & (act==2 | act==3)
** centrist Commission (close pivot_qmv pivot_top)
replace PROCrp=comm        if pivot_qmv<=comm & comm<=pivot_top & 2*pivot_qmv>=pivot_top & cou_rule==2 & ep_rule==1 & (act==2 | act==3)
** moderately reformist Commission (distant pivot_qmv pivot_top)
replace PROCrp=2*pivot_qmv if pivot_qmv<=comm & comm<=pivot_top & comm>=2*pivot_qmv & 2*pivot_qmv<=pivot_top & cou_rule==2 & ep_rule==1 & (act==2 | act==3) 
** reformist Commission (close pivot_qmv pivot_top)
replace PROCrp=pivot_top   if comm>=pivot_top & 2*pivot_qmv>=pivot_top & cou_rule==2 & ep_rule==1 & (act==2 | act==3) 
* second step parliamentary constraint
* strongly conservative parliament (ep_1<pivot_u): no effect, equal to qmv consultation
* moderately conservative parliament (pivot_u<ep_1<pivot_qmv) & conservative commission (comm<=2*ep_1): no effect, equal to qmv consultation 
* moderately conservative parliament (pivot_u<ep_1<pivot_qmv) & reformist commission (comm>=2*ep_1)
replace PROCrp=2*ep_1 if pivot_u<=ep_1 & ep_1<=pivot_qmv & comm>=2*ep_1 & 2*ep_1<=pivot_top & cou_rule==2 & ep_rule==1 & (act==2 | act==3)  
* reformist parliament (ep_1>pivot_qmv): no effect, equal to qmv consultation

* pause

*** OLP with qmv min14 (acts 4, 9)
* The set of proposals that can be adopted is L=A_3 ∩ A_p ∩ M
* strongly conservative Commission
egen pred2=rowmin(ep_1 pivot_min14) if ((comm<=pivot_min14 & pivot_min14<=ep_1) | (comm<=ep_1 & ep_1<=pivot_min14)) & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9) 
replace PROCrp=pred2 if pred2!=.
drop pred2
* moderately conservative Commission (close pivot_min14 & ep_1)
replace PROCrp=comm 	if pivot_min14<=comm & comm<=ep_1 			& ep_1<=2*pivot_min14 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
replace PROCrp=comm		if ep_1<=comm 		 & comm<=pivot_min14    & pivot_min14<=2*ep_1 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
* moderately conservative Commission (distant pivot_min14 & ep_1)
replace PROCrp=comm 	if pivot_min14<=comm & comm<=ep_1 			& 2*pivot_min14<=ep_1 & comm<=2*pivot_min14 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
replace PROCrp=comm		if ep_1<=comm 		 & comm<=pivot_min14    & 2*ep_1<=pivot_min14 & comm<=2*ep_1		& ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
* moderately reformist Commission (distant pivot_min14 & ep_1)
replace PROCrp=2*pivot_min14 	if pivot_min14<=comm & comm<=ep_1 			& 2*pivot_min14<=ep_1 & 2*pivot_min14<=comm	& ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)    
replace PROCrp=2*ep_1			if ep_1<=comm 		 & comm<=pivot_min14    & 2*ep_1<=pivot_min14 & 2*ep_1<=comm 		& ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
* strongly reformist Commission (close pivot_min14 & ep_1)
replace PROCrp=ep_1 		if pivot_min14<=ep_1 & ep_1<=comm 			& ep_1<=2*pivot_min14 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
replace PROCrp=pivot_min14	if ep_1<=pivot_min14 & pivot_min14<=comm    & pivot_min14<=2*ep_1 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
* strongly reformist Commission (distant pivot_min14 & ep_1)
replace PROCrp=2*pivot_min14 	if pivot_min14<=ep_1 & ep_1<=comm 		   & ep_1>=2*pivot_min14 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  
replace PROCrp=2*ep_1 			if ep_1<=pivot_min14 & pivot_min14<=comm   & pivot_min14>=2*ep_1 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==4 | act==9)  

* pause

*** OLP with qmv min9 (acts 8, 10, 12, 13)
* The set of proposals that can be adopted is L=A_3 ∩ A_p ∩ M
* strongly conservative Commission
egen pred2=rowmin(ep_1 pivot_min9) if ((comm<=pivot_min9 & pivot_min9<=ep_1) | (comm<=ep_1 & ep_1<=pivot_min9)) & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12) 
replace PROCrp=pred2 if pred2!=.
drop pred2
* moderately conservative Commission (close pivot_min9 & ep_1)
replace PROCrp=comm 	if pivot_min9<=comm & comm<=ep_1 			& ep_1<=2*pivot_min9 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
replace PROCrp=comm		if ep_1<=comm 		 & comm<=pivot_min9    & pivot_min9<=2*ep_1 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
* moderately conservative Commission (distant pivot_min9 & ep_1)
replace PROCrp=comm 	if pivot_min9<=comm & comm<=ep_1 			& 2*pivot_min9<=ep_1 & comm<=2*pivot_min9 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
replace PROCrp=comm		if ep_1<=comm 		 & comm<=pivot_min9    & 2*ep_1<=pivot_min9 & comm<=2*ep_1		& ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
* moderately reformist Commission (distant pivot_min9 & ep_1)
replace PROCrp=2*pivot_min9 	if pivot_min9<=comm & comm<=ep_1 			& 2*pivot_min9<=ep_1 & 2*pivot_min9<=comm	& ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)    
replace PROCrp=2*ep_1			if ep_1<=comm 		 & comm<=pivot_min9    & 2*ep_1<=pivot_min9 & 2*ep_1<=comm 		& ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
* strongly reformist Commission (close pivot_min9 & ep_1)
replace PROCrp=ep_1 		if pivot_min9<=ep_1 & ep_1<=comm 			& ep_1<=2*pivot_min9 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
replace PROCrp=pivot_min9	if ep_1<=pivot_min9 & pivot_min9<=comm    & pivot_min9<=2*ep_1 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
* strongly reformist Commission (distant pivot_min9 & ep_1)
replace PROCrp=2*pivot_min9 	if pivot_min9<=ep_1 & ep_1<=comm 		   & ep_1>=2*pivot_min9 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)  
replace PROCrp=2*ep_1 			if ep_1<=pivot_min9 & pivot_min9<=comm   & pivot_min9>=2*ep_1 & ep_rule==2 & issue_id!=issue_id[_n+1] & (act==8 | act==10 | act>=12)   

order PROCrp pivot_u pivot_qmv pivot_min14 pivot_min9 pivot_count14 pivot_count9 pivot_pop, after(outcome)

collapse PROCrp outcome, by(issue_id)
label variable PROCrp "procedural model solution, with reference point"

* Compute means of absolute differences between outcomes and model predictions
gen ad=abs(PROCrp-outcome)
label variable ad "absolute difference bw PROCrp outcome" 
egen mad = mean(ad)
label variable mad "mean absolute error per issue (PROCrp)" 

